<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    /* function cat(name, color, type) {
        var obj = { // new Object();
            name: name,
            color: color,
            type: type,

            // 公有的属性和方法 (每个对象都有的)
            species: "Cat",
            call: function () {
                console.log("喵喵");
            },
            skill: function () {
                console.log("捉老鼠");
            }
        }
        return obj;
    }

    var Tom = cat("Tom", "black", "黑猫");
    console.log(Tom, Tom instanceof cat, Tom instanceof Object);

    var Kitty = cat("Kitty", "black", "田园");
    console.log(Kitty); */


    // debugger;
    // 面向对象的封装 => 自定义构造函数 

    function Cat(name, color, type) {
        // {}
        // this -> {}

        this.name = name;
        this.color = color;
        this.type = type;

        // 公有属性和方法重复创建  => 栈内存
        this.species = "Cat";
        this.call = function () {
            console.log("喵喵");
        }
        this.skill = function () {
            console.log("捉老鼠");
        }

        // return this;
    }

    // 通过构造函数创建了一个实例化对象
    // 调用构造函数 => 执行构造函数中的上下文  => 返回新的实例化对象 
    var Tom = new Cat("Tom", "black", "黑猫");
    console.log(Tom, Tom instanceof Cat);

    var Kitty = new Cat("Kitty", "pink", "田园");
    console.log(Kitty, Kitty instanceof Cat);
</script>

</html>